<template>
  <div class="favor">
    <headers></headers>
    
    <!-- 页面头部 -->
    <div class="page-header">
      <div class="header-content">
        <h1>我的收藏</h1>
        <p>珍藏您喜爱的旅游线路</p>
      </div>
    </div>

    <!-- 收藏列表 -->
    <div class="content-section">
      <div class="favorites-grid">
        <div class="favorite-card" v-for="(item,index) in tableData" :key="index" @click="toInfo(item.lineId)">
          <div class="card-image" :style="{ backgroundImage: `url(${item.images.split(',')[0]})` }">
            <div class="card-overlay">
              <div class="view-details">
                <i class="el-icon-view"></i>
                查看详情
              </div>
            </div>
          </div>
          <div class="card-content">
            <h3>{{item.name}}</h3>
            <p class="description">{{item.introduce}}</p>
            <div class="card-footer">
              <span class="favorite-date" v-if="item.createTime">
                <i class="el-icon-time"></i>
                收藏于 {{new Date(item.createTime).toLocaleDateString()}}
              </span>
              <el-button 
                type="text" 
                class="view-btn"
                @click.stop="toInfo(item.lineId)"
              >
                <i class="el-icon-right"></i>
                查看详情
              </el-button>
            </div>
          </div>
        </div>
      </div>

      <!-- 空状态 -->
      <div class="empty-state" v-if="tableData.length === 0">
        <i class="el-icon-star-off"></i>
        <p>暂无收藏内容</p>
        <el-button type="primary" @click="$router.push('/line')">去发现线路</el-button>
      </div>

      <!-- 分页 -->
      <div class="pagination-container" v-if="tableData.length > 0">
        <el-pagination
          background
          :page-size="search.pageSize"
          layout="prev, pager, next"
          @current-change="handleCurrentChange"
          :total="total">
        </el-pagination>
      </div>
    </div>

    <bottoms></bottoms>
  </div>
</template>

<script>
import { getSysFavorPage } from '../../api/api'
import headers from '@/components/header'
import bottoms from '@/components/bottom'

export default {
  name: 'Favorites',
  components: {
    headers,
    bottoms
  },
  data() {
    return {
      search: {
        userId: "",
        pageSize: 12,
        pageNumber: 1,
      },
      total: 100,
      tableData: [],
    }
  },
  methods: {
    getSysFavorPage() {
      getSysFavorPage(this.search).then(res => {
        if (res.code == 1000) {
          this.tableData = res.data.records
          this.total = res.data.total
        }
      })
    },
    toInfo(id) {
      this.$router.push("/lineInfo?id=" + id)
    },
    handleCurrentChange(val) {
      this.search.pageNumber = val
      this.getSysFavorPage()
    }
  },
  mounted() {
    this.search.userId = JSON.parse(window.localStorage.getItem("user_info")).id
    this.getSysFavorPage()
  }
}
</script>

<style scoped>
.favor {
  min-height: 100vh;
  background-color: #f8f9fa;
}

/* 页面头部样式 */
.page-header {
  background: linear-gradient(135deg, #FF5722 0%, #E64A19 100%);
  background-size: cover;
  background-position: center;
  height: 250px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  text-align: center;
  margin-bottom: 40px;
}

.header-content {
  max-width: 800px;
  padding: 0 20px;
}

.header-content h1 {
  font-size: 2.5rem;
  margin-bottom: 1rem;
  font-weight: bold;
  text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

.header-content p {
  font-size: 1.2rem;
  margin-bottom: 2rem;
  text-shadow: 1px 1px 2px rgba(0,0,0,0.3);
}

/* 内容区域样式 */
.content-section {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px 40px;
}

/* 收藏网格 */
.favorites-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 30px;
  margin-bottom: 40px;
}

/* 收藏卡片样式 */
.favorite-card {
  background: white;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 6px rgba(0,0,0,0.1);
  transition: transform 0.3s ease;
  cursor: pointer;
}

.favorite-card:hover {
  transform: translateY(-5px);
}

.card-image {
  height: 200px;
  background-size: cover;
  background-position: center;
  position: relative;
}

.card-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.favorite-card:hover .card-overlay {
  opacity: 1;
}

.view-details {
  color: white;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.view-details i {
  font-size: 1.3rem;
}

.card-content {
  padding: 20px;
}

.card-content h3 {
  font-size: 1.25rem;
  color: #303133;
  margin-bottom: 10px;
  font-weight: 500;
}

.description {
  color: #606266;
  font-size: 0.9rem;
  line-height: 1.6;
  margin-bottom: 15px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #909399;
  font-size: 0.9rem;
}

.favorite-date {
  display: flex;
  align-items: center;
  gap: 5px;
}

.view-btn {
  color: #409EFF;
  padding: 0;
}

.view-btn i {
  margin-left: 4px;
}

/* 空状态样式 */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: #909399;
}

.empty-state i {
  font-size: 48px;
  margin-bottom: 16px;
}

.empty-state p {
  font-size: 16px;
  margin-bottom: 24px;
}

/* 分页容器样式 */
.pagination-container {
  display: flex;
  justify-content: center;
  margin: 40px 0 0;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .page-header {
    height: 200px;
  }

  .header-content h1 {
    font-size: 2rem;
  }

  .header-content p {
    font-size: 1rem;
  }

  .favorites-grid {
    grid-template-columns: 1fr;
  }
}
</style>